package org.jeecg.demo.wx.util;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;


@Data
public class PageData<T> {

    @ApiModelProperty(value = "当前页", example = "1")
    long current;
    @ApiModelProperty(value = "每页显示的记录数", example = "10")
    long size;
    @ApiModelProperty(value = "总记录数", example = "10")
    long total;
    @ApiModelProperty(value = "总页数", example = "1")
    long pages;
    @ApiModelProperty(value = "数据")
    List<T> records;

    /**
     * page转pageData
     */
    public static <T> PageData<T> convertPageData(IPage<?> page, List<T> data) {
        PageData<T> pageData = new PageData();
        pageData.setRecords(data);
        pageData.setCurrent(page.getCurrent());
        pageData.setSize(page.getSize());
        pageData.setTotal(page.getTotal());
        pageData.setPages(page.getPages());
        return pageData;
    }

    /**
     * page转pageData
     */
    public static <T> PageData convertPageData(IPage<T> page) {
        PageData<T> pageData = new PageData();
        pageData.setRecords(page.getRecords());
        pageData.setCurrent(page.getCurrent());
        pageData.setSize(page.getSize());
        pageData.setTotal(page.getTotal());
        pageData.setPages(page.getPages());
        return pageData;
    }

    /**
     * pageData转pageData
     */
    public static <T> PageData<T> convert(PageData<?> page, List<T> data) {
        PageData<T> n = new PageData<T>();
        n.setCurrent(page.getCurrent());
        n.setSize(page.getSize());
        n.setTotal(page.getTotal());
        n.setPages(page.getPages());
        n.setRecords(data);
        return n;
    }
}
